#include "ModelComposite.h"
#include <algorithm>

ModelComposite::ModelComposite()
{
}

void ModelComposite::traverse(const Event& event)
{
    Model::traverse(event);
    for (Children::iterator it = m_children.begin(); it != m_children.end(); ++it)
    {
        (*it)->traverse(event);
    }
}

void ModelComposite::addChild(Model* element)
{
    m_children.push_back(ModelPtr(element));
}

void ModelComposite::eraseChildren(void)
{
    m_children.clear();
}

void ModelComposite::removeChild(long idToRemove)
{
    for (Children::iterator it = m_children.begin(); it != m_children.end(); ++it)
    {
        if ((*it)->getId() == idToRemove)
        {
            m_children.erase(it);
            return;
        }
    }
}

void ModelComposite::collectChanges(NetworkEvents& events)
{
    Model::collectChanges(events);
    for (Children::iterator it = m_children.begin(); it != m_children.end(); ++it)
    {
        (*it)->collectChanges(events);
    }
}

ModelComposite::~ModelComposite()
{
}

